/**
 * Created by yw.libj02095 on 2017/3/8.
 */
var strJSON = {
    //将从form中通过$('#refer').serialize()获取的值转成json
    formToJson: function (data) {
        data=data.replace(/&/g,"\",\"");
        data=data.replace(/=/g,"\":\"");
        data="{\""+data+"\"}";
        return data;
    }
};


var strDataJSON = {
    //将从form中通过$('#refer').serialize()获取的值转成json
    formToJson: function (data) {
        data=data.replace(/&/g,"\",\"");
        data=data.replace(/=/g,"\":\"");
        data="\"data\":{\""+data+"\"}";
        return data;
    }
};
// 设定时间 - 当前时间 转换方法
function timeDifference(str){
    var strYear = str.substring(0,4)
    var strMonth = str.substring(4,6)
    var strDay = str.substring(6,8)

    var date = strYear + "-" + strMonth + "-" + strDay

    var endDate = new Date(Date.parse(date)); //创建时间对象
    var newDate = new Date(); //获取现在的时间

    var s=(newDate.getTime() - endDate.getTime())/1000;  //时间差的秒数
    var day=Math.floor(s/86400); //获取天数

    return day
}

// 转换方法YYYY-MM-DD
function ifDataLine(str){
    var strYear = str.substring(0,4)
    var strMonth = str.substring(4,6)
    var strDay = str.substring(6,8)

    var date = strYear + "-" + strMonth + "-" + strDay;
    return date
}
// 转换方法YYYYMMDD
function ifDleLine(str){
    var strYear = str.substring(0,4)
    var strMonth = str.substring(5,7)
    var strDay = str.substring(8,10)

    var date = strYear + strMonth + strDay;
    return date
}


//时间转换方法
function ifData(data){
    if(data==null){
        return '';
    }
    var time = new Date(data);
    var year = time.getFullYear();
    var month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
    var day = (time.getDate()) < 10 ? "0" + (time.getDate()) : (time.getDate());

    var newTime = year + "-" + month + "-" + day ;
    return newTime
}
//时间转换String
function gfData(data){
    if(data=="" || data==null){
        return "";
    }
    var now = new Date(data);
    var year = now.getFullYear();
    var month =(now.getMonth() + 1).toString();
    var day = (now.getDate()).toString();
    if (month.length == 1) {
        month = "0" + month;
    }
    if (day.length == 1) {
        day = "0" + day;
    }
    var dateTime = year + month +  day;
    return dateTime
}

//默认时间为本地时间
function timeDate(obj){
    var date = Date.parse(new Date())
    var newDate = ifData(date)
    var dataTime = newDate.replace(/-/ig,'')
    return $(obj).val(dataTime)
}

function timeDate1(obj){
    var date = Date.parse(obj)
    var newDate = ifData(date)
    var dataTime = newDate.replace(/-/ig,'')
    return dataTime
}

//默认时间为本地时间
function ifNull(data){
    if(data==null || data == "null"){
        return "-"
    }else{
        return data
    }
}
//ifNull，置空''
function ifNull2EmptyStr(data){
    if(data==null || data == "null"){
        return "";
    }else{
        return data;
    };
}

//时间转换方法
function ifTime(data){
    if(data==null || data == ''){
        return '';
    }
    var time = new Date(data);
    var year = time.getFullYear();
    var month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
    var day = (time.getDate()) < 10 ? "0" + (time.getDate()) : (time.getDate());

    // 获取小时
    var hours = (time.getHours()) < 10 ? "0" + (time.getHours()) : (time.getHours())
    // 获取分钟
    var minutes = (time.getMinutes()) < 10 ? "0" + (time.getMinutes()) : (time.getMinutes())
    // 获取秒
    var seconds = (time.getSeconds()) < 10 ? "0" + (time.getSeconds()) : (time.getSeconds())

    var newTime = year + "-" + month + "-" + day +" "+ hours + ":" + minutes +":" + seconds ;
    return newTime
}

//时间转换方法 年月日时分
function TimeHours(data){
    if(data==null){
        return '';
    }
    var time = new Date(data);
    var year = time.getFullYear();
    var month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
    var day = (time.getDate()) < 10 ? "0" + (time.getDate()) : (time.getDate());

    // 获取小时
    var hours = (time.getHours()) < 10 ? "0" + (time.getHours()) : (time.getHours())
    // 获取分钟
    var minutes = (time.getMinutes()) < 10 ? "0" + (time.getMinutes()) : (time.getMinutes())
    // 获取秒
    var seconds = (time.getSeconds()) < 10 ? "0" + (time.getSeconds()) : (time.getSeconds())

    var newTime = year + "-" + month + "-" + day +" "+ hours + ":" + minutes ;
    return newTime
}

//时间转换方法
function ifDataTime(data){
    if(data==null || data == ''){
        return '';
    }
    var time = new Date(data);
    var year = time.getFullYear();
    var month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
    var day = (time.getDate()) < 10 ? "0" + (time.getDate()) : (time.getDate());
    var newTime = year + "-" + month + "-" + day ;
    return newTime
}
 //获取本地时间
function today(){
    var today=new Date();
    var h=today.getFullYear();
    var m=today.getMonth()+1;
    var d=today.getDate();
    var hh=today.getHours();
    var mm=today.getMinutes();
    var ss=today.getSeconds();
    m= m<10?"0"+m:m;
    d= d<10?"0"+d:d;
    // hh = hh < 10 ? "0" + hh:hh;
    // mm = mm < 10 ? "0" +  mm:mm;
    // ss = ss < 10 ? "0" + ss:ss;
    // return h+"-"+m+"-"+d+" "+hh+":"+mm+":"+ss;
    return h+""+m+""+d;
}

/*待处理记录导航*/
function procedureClick(obj) {
    Hui_admin_tab(obj);
}
//验证纯数字整数
function rxpNum(obj) {
    var r = /^\d+$/;
    if(!r.test($(obj).val())){
        return $(obj).val("");
    }
}
//验证纯数字整数且不能为0
function rxpNum0(obj) {
    var r = /^[1-9]\d*$/;
    if(!r.test($(obj).val())){
        return $(obj).val("");
    }
}
//验证纯数字整数
function rxpNum30(obj) {
    var num31 = /^[0-9*]{9,30}$/;
    if(!num31.test($(obj).val())){
        return $(obj).val("");
    }
}
 //四位小数
function rxp(obj){
    var r = /^\d+(\.\d{0,4})?$/;
    if(!r.test(obj.value)){
        obj.value = "";
        return;
    }
}
 //只能输入纯数字
function mobReg(obj){
    var mobileReg = /^\d+$/;
    if(!mobileReg.test(obj.value)){
        obj.value = "";
        return;
    }
}

//验证手机号和座机
function mobRegIphone(obj){
    var mobileReg = /^\d[\d\-]*$/;
    if(!mobileReg.test(obj.value)){
        obj.value = "";
        return;
    }
}
//正则验证邮箱
function rxpMail(option) {
    var reg = /^[0-9a-zA-Z_.-]+[@][0-9a-zA-Z_.-]+([.][a-zA-Z]+){1,2}$/
    if(option.value != '' && !reg.test(option.value)) {
        console.log("邮箱格式不正确")
    }
}
//验证非汉字
function isChinse(value) {
    var re = /[^\u4e00-\u9fa5]+$/;
    if (re.test(value)) {
        return false;
    } else {
        return true;
    }
}

 //href链接 取参数，不限制多个参数
function GetQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null)
        return unescape(decodeURI(r[2]));
    return null;
}
//var fundCode = GetQueryString("fundCode");



/*待处理记录导航*/
function procedureClick(obj) {
    Hui_admin_tab(obj);
}

/*最新tab标题栏列表*/
function min_titleList() {
    var topWindow = $(window.parent.parent.document),
        show_nav = topWindow.find("#min_title_list"),
        aLi = show_nav.find("li");
}

/*菜单导航*/
function Hui_admin_tab(obj) {
    var bStop = false,
        bStopIndex = 0,
        href = $(obj).attr('data-href'),
        title = $(obj).attr("data-title"),
        topWindow = $(window.parent.parent.document),
        show_navLi = topWindow.find("#min_title_list li"),
        iframe_box = topWindow.find("#iframe_box");
    if (title == "") {
        alert("data-title属性不能为空");
        return false;
    }
    show_navLi.each(function () {
        if ($(this).find('span').attr("data-href") == href) {
            bStop = true;
            bStopIndex = show_navLi.index($(this));
            return false;
        }
    });
    if (!bStop) {
        creatIframe(href, title);
        min_titleList();
    }
    else {
        show_navLi.removeClass("active").eq(bStopIndex).addClass("active");
        iframe_box.find(".show_iframe").hide().eq(bStopIndex).show().find("iframe").attr("src", href);
    }
}

/*创建iframe*/
function creatIframe(href, titleName) {
    var topWindow = $(window.parent.parent.document),
        show_nav = topWindow.find('#min_title_list'),
        iframe_box = topWindow.find('#iframe_box'),
        iframeBox = iframe_box.find('.show_iframe'),
        $tabNav = topWindow.find(".acrossTab"),
        $tabNavWp = topWindow.find(".Hui-tabNav-wp"),
        $tabNavmore = topWindow.find(".Hui-tabNav-more");
    var taballwidth = 0;

    show_nav.find('li').removeClass("active");
    show_nav.append('<li class="active"><span data-href="' + href + '">' + titleName + '</span><i></i><em></em></li>');

    var $tabNavitem = topWindow.find(".acrossTab li");
    if (!$tabNav[0]) {
        return
    }
    $tabNavitem.each(function (index, element) {
        taballwidth += Number(parseFloat($(this).width() + 60))
    });
    $tabNav.width(taballwidth + 25);
    var w = $tabNavWp.width();
    if (taballwidth + 25 > w) {
        $tabNavmore.show()
    }
    else {
        $tabNavmore.hide();
        $tabNav.css({left: 0})
    }
    iframeBox.hide();
    iframe_box.append('<div class="show_iframe"><div class="loading"></div><iframe frameborder="0" src=' + href + '></iframe></div>');
    var showBox = iframe_box.find('.show_iframe:visible');
    showBox.find('iframe').load(function () {
        showBox.find('.loading').hide();
    });
}

//去除输入框空格
function replaceSpace(value, id) {
    var val = value.replace(/\s/g, '');
    document.getElementById(id).value = val;
}

/*时间转换CST*/
function setTimeCST(data){
    var time = new Date(new Date(data).valueOf() - 60*60*1000*14);

    var year = time.getFullYear();
    var month = (time.getMonth() + 1) < 10 ? "0" + (time.getMonth() + 1) : (time.getMonth() + 1);
    var day = (time.getDate()) < 10 ? "0" + (time.getDate()) : (time.getDate());

    // 获取小时
    var hours = (time.getHours()) < 10 ? (time.getHours()) : (time.getHours())
    //var hours = (time.getHours()) < 10 ? "0" + (time.getHours()) : (time.getHours())
    // 获取分钟
    var minutes = (time.getMinutes()) < 10 ? "0" + (time.getMinutes()) : (time.getMinutes())
    // 获取秒
    var seconds = (time.getSeconds()) < 10 ? "0" + (time.getSeconds()) : (time.getSeconds())

    var newTime = year + "-" + month + "-" + day +" "+ hours + ":" + minutes +":" + seconds ;
    return newTime
}

//保留后4位，前面用****代替
function lastFourDecimal(num){
    if(num!=null){
        var newDecimal = num.substring(num.length-4)
        return '****'+newDecimal
    }else{
        return '--'
    }

}
/*金额以逗号分隔显示*/
function fmoney(s) {
    if(s == null|| s == '') {
        return '';
    }
    var str = s.toFixed(2)+'';
    var intSum = str.substring(0,str.indexOf(".")).replace(/\B(?=(?:\d{3})+$)/g, ',');//取到整数bai部分du
    var dot = str.substring(str.length,str.indexOf("."))//取到小数部分
    var ret = intSum + dot;
    return ret;
}
/*获取时间 只要时分秒*/
function getTime(data){
    if(data==null || data == ''){
        return '';
    }
    var time = new Date(data);
    // 获取小时
    var hours = (time.getHours()) < 10 ? "0" + (time.getHours()) : (time.getHours())
    // 获取分钟
    var minutes = (time.getMinutes()) < 10 ? "0" + (time.getMinutes()) : (time.getMinutes())
    // 获取秒
    var seconds = (time.getSeconds()) < 10 ? "0" + (time.getSeconds()) : (time.getSeconds())
    var newTime = hours + ":" + minutes +":" + seconds ;
    return newTime
}
//去除输入框空格
function replaceSpace(value, id) {
    var val = value.replace(/\s/g, '');
    document.getElementById(id).value = val;
}

/**
 * 获取兼容格式的时间<br>
 * 将yyyy-MM-dd HH:mm:ss格式的转为yyyy/MM/dd HH:mm:ss格式,以兼容Chrome/FireFox/IE等浏览器
 * @param dateTime
 * @returns {null|Date}
 */
function getCompatibleTime(dateTime) {
    if (dateTime == null || dateTime === '') {
        return null;
    }
    dateTime = dateTime.replace(/-/g, "/");
    return new Date(dateTime);
}